package org.tagging.service.impl.malay;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.tagging.dao.malay.UnknownWordMalayMapper;
import org.tagging.model.UnknownWord;
import org.tagging.model.UnknownWordMalay;
import org.tagging.service.UnknownWordService;
import org.tagging.service.impl.other.ClientUserServiceImpl;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class UnknownWordMalayServiceImpl implements UnknownWordService<UnknownWordMalay> {
    @Resource
    private UnknownWordMalayMapper unknownWordMalayMapper;
    @Autowired
    private ClientUserServiceImpl userService;

    @Override
    public List<UnknownWordMalay> queryByTagId(Integer id) {
        return unknownWordMalayMapper.queryByTagId(id);
    }

    @Override
    public void update(UnknownWord unknownWord) {
        Integer userId = userService.retrieveCurrentUserId();
        unknownWord.setUpdateTime(LocalDateTime.now());
        unknownWord.setUpdateBy(userId);
        unknownWordMalayMapper.updateSelective(unknownWord);
    }

    @Override
    public UnknownWordMalay queryById(Integer id) {
        return unknownWordMalayMapper.queryById(id);
    }

    @Override
    public void add(UnknownWord unknownWord) {
        Integer userId = userService.retrieveCurrentUserId();
        unknownWord.setUpdateTime(LocalDateTime.now());
        unknownWord.setUpdateBy(userId);
        unknownWordMalayMapper.insertSelective(unknownWord);
    }

    public List<UnknownWordMalay> queryByTimePeriod(LocalDateTime startTime, LocalDateTime endTime, int mode) {
        return unknownWordMalayMapper.queryByTimePeriod(startTime, endTime, mode);
    }
}
